<template>
<div>
  <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px">
    <el-breadcrumb-item :to="{ path:'/blank' }"><i class="el-icon-user-solid"></i>系统管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
  </el-breadcrumb>
  <el-divider></el-divider>
  <el-row style="text-align: left">
    <el-select v-model="selectUser.roleId" :value="selectUser.roleId" placeholder="角色" style="width: 180px" clearable @visible-change="selectUserByUser">
      <el-option v-for="item in roleArr" :label="item.roleName" :value="item.id" :key="item.id"></el-option>
    </el-select>
    <el-select v-model="selectUser.majorId" :value="selectUser.majorId" placeholder="专业" style="width: 180px;margin: 0 5px" clearable @visible-change="selectUserByUser">
      <el-option v-for="item in majorArr" :label="item.majorName" :value="item.id" :key="item.id"></el-option>
    </el-select>
    <el-select v-model="selectUser.classId" :value="selectUser.classId" placeholder="班级" style="width: 180px" clearable @visible-change="selectUserByUser">
      <el-option v-for="item in classArr" :label="item.className" :value="item.id" :key="item.id"></el-option>
    </el-select>
    <el-input style="width: 180px;margin: 0 5px" placeholder="用户名" prefix-icon="el-icon-search" v-model="selectUser.username" @keydown.native.enter="selectUserByUser"></el-input>
    <el-input style="width: 180px;" placeholder="姓名" prefix-icon="el-icon-search" v-model="selectUser.trueName" @keydown.native.enter="selectUserByUser"></el-input>
    <el-button type="success" size="medium" @click="selectUserByUser" icon="el-icon-search" style="margin: 0 10px">查询</el-button>
    <el-button type="success" size="medium" icon="el-icon-refresh" @click="LoadUserList">刷新</el-button>
  </el-row>

  <el-row style="float: left;margin: 10px 0">
    <el-button type="primary" icon="el-icon-plus" @click="goUserAdd">添加用户</el-button>
    <el-button type="primary" v-if="isMultipleSelection" plain @click="openStatus">启用</el-button>
    <el-button type="warning" v-if="isMultipleSelection"  plain @click="closeStatus">禁用</el-button>
    <el-button type="danger" v-if="isMultipleSelection"  plain @click="openDeleteByIds">删除</el-button>
  </el-row>

  <el-table ref="multipleTable" :data="userArr" :border="true" tooltip-effect="dark" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="60" align="center"></el-table-column>
    <el-table-column label="id" prop="id" show-overflow-tooltip width="60px" align="center"></el-table-column>
    <el-table-column label="用户名" show-overflow-tooltip header-align="center">
      <template slot-scope="scope">
        <a  style="text-decoration: none;color: #409EFF;cursor:pointer" @click="openUpdatePassword(scope.row)">{{ scope.row.username}}</a>
      </template>
    </el-table-column>
    <el-table-column label="真实姓名" prop="trueName" show-overflow-tooltip  align="center"></el-table-column>
    <el-table-column label="角色名" prop="roleName" show-overflow-tooltip  align="center"></el-table-column>
    <el-table-column label="电话" prop="phone" show-overflow-tooltip width="120px" align="center"></el-table-column>
    <el-table-column label="邮箱" prop="email" show-overflow-tooltip align="center"></el-table-column>
    <el-table-column label="专业名" prop="majorName" show-overflow-tooltip  width="100px" align="center"></el-table-column>
    <el-table-column label="班级名" prop="className" show-overflow-tooltip  width="100px" align="center"></el-table-column>
    <el-table-column label="用户状态" prop="status" show-overflow-tooltip  width="100px" align="center">
      <template slot-scope="scope">
        <el-switch v-model="scope.row.status" @change="openUpdateStatus(scope.row)" active-value="0" inactive-value="1" active-color="#13ce66">
        </el-switch>
      </template>
    </el-table-column>
    <el-table-column  label="操作" header-align="center" align="center" width="100">
      <template slot-scope="scope">
        <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="getStandard(scope.row)"></el-button>
        <el-button type="danger" size="mini" icon="el-icon-delete" circle @click="openDelete(scope.row)"></el-button>
      </template>
    </el-table-column>
  </el-table>


  <div style="text-align: right;margin: 10px auto">
    <el-pagination layout="total,prev, pager, next" @current-change="changePage" :total="total" :current-page="currentPage" :page-size="pageSize"></el-pagination>
  </div>

  <el-dialog title="修改密码" :visible.sync="userUpdatepassword" width="600px">
    <el-form :model="ediFormNamePassword" :rules="rules" ref="editForm" :label-width="formLabelWidth" align="left" style="margin: -10px 0 -20px 0">
      <el-form-item prop="username" label="用户名" >
        <el-input type="text" placeholder="账号" readonly prefix-icon="el-icon-user" v-model="ediFormNamePassword.username"></el-input>
      </el-form-item>
      <el-form-item label="用户名">
        <el-input type="password" placeholder="密码" prefix-icon="el-icon-user" v-model="ediFormNamePassword.password"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="userUpdatepassword = false">取 消</el-button>
      <el-button type="primary" @click="updateUserPassword">确 定</el-button>
    </div>
  </el-dialog>


  <el-dialog title="用户修改" :visible.sync="dialogFormVisible" width="640px">
    <el-form :model="editForm" :rules="rules" ref="editForm" :label-width="formLabelWidth" align="left" style="margin: -10px 0 -20px 0">
      <el-form-item prop="username" label="用户名">
        <el-input type="text" placeholder="账号" prefix-icon="el-icon-user" v-model="editForm.username"></el-input>
      </el-form-item>
      <el-form-item prop="trueName" label="真实姓名">
        <el-input type="text" placeholder="真实姓名" prefix-icon="el-icon-user" v-model="editForm.trueName"></el-input>
      </el-form-item>
      <el-form-item prop="phone" label="电话">
        <el-input type="text" placeholder="电话" prefix-icon="el-icon-phone" v-model="editForm.phone"></el-input>
      </el-form-item>
      <el-form-item prop="email" label="邮箱">
        <el-input type="text" placeholder="邮箱" prefix-icon="el-icon-s-platform" v-model="editForm.email"></el-input>
      </el-form-item>
      <el-form-item prop="majorId" label="专业id">
        <template>
          <div style="text-align: left">
            <el-select v-model="editForm.majorId" :value="editForm.majorId" :lable="editForm.majorName" @change="getClassUpdateArr">
              <el-option v-for="item in majorArr" :label="item.majorName" :value="item.id" :key="item.id"></el-option>
            </el-select>
          </div>
        </template>
      </el-form-item>
      <el-form-item prop="classId" label="班级id">
        <template>
          <div style="text-align: left">
            <el-select v-model="editForm.classId" :value="editForm.classId" :lable="editForm.className">
              <el-option v-for="item in classUpdateArr" :label="item.className" :value="item.id" :key="item.id"></el-option>
            </el-select>
          </div>
        </template>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="openUpdateUser">确 定</el-button>
    </div>
  </el-dialog>


</div>
</template>

<script>
export default {
  data(){
    return{
      //输入框
      inputs:'',
      //分页参数
      total:0,
      pageSize:0,
      currentPage:1,
      dialogFormVisible:false,
      userUpdatepassword:false,
      isMultipleSelection:false,
      //数据数组
      userArr:[],
      roleArr:[{
        roleName:'',
        id:''
      }],
      majorArr: [{id:'',majorName:''}],
      classArr:[],
      classUpdateArr:[],
      //下拉选选中的值
      selectUser:{
        roleId:'',
        majorId:'',
        classId:'',
        username:'',
        trueName:''
      },
      multipleSelection:[],
      formLabelWidth:'120px',
      //修改用户数组
      editForm:{
          username: '',
          password: '',
          trueName:'',
          phone:'',
          email:'',
          majorId:'',
          majorName:'',
          classId:'',
          className:''
        },
      ediFormNamePassword:{
        id:'',
        username:'',
        password:''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 4, max: 15, message: '长度在 4 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 4, max: 15, message: '长度在 4 到 15 个字符', trigger: 'blur' },
          {pattern:/^([1-9A-Za-z]*)$/,message:'请输入以字母和数字组成的密码',trigger: 'blur'}
        ],
        trueName: [
          { required: true, message: '请输入真实姓名', trigger: 'blur' },
          {min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur'}
        ],
        phone:[
          { required: true, message: '请输入电话', trigger: 'blur' },
          {pattern:/^1\d{10}$/,message:'请输入正确的电话',trigger: 'blur'}
        ],
        email:[
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          /*^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$*/
          {pattern:/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,message:'请输入邮箱',trigger: 'blur'}
        ],
        majorId:[
          { required: true, message: '专业不能为空', trigger: 'blur' }
        ],
        classId:[
          { required: true, message: '班级不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    //去新增页面
    goUserAdd(){
      this.$router.push("/user/add-new")
    },
    //修改密码
    openUpdatePassword(user){
      console.log(user);
      let url = "http://localhost:9281/user-getStandardUpdatePasswordVo/"+user.id;
      console.log(url);
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).get(url).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.ediFormNamePassword = jsonResult.data;
          this.userUpdatepassword= true;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {

            }
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定'
          });
        }
      })
    },
    //修改用户时专业选择bug,选择专业后，选择班级，然后选择专业，会导致非本专业班级出现在本专业中
    //修改用户
    updateUserPassword(){
      let url = "http://localhost:9281/user-update-password/";
      console.log(url);
      let formData = this.qs.stringify(this.ediFormNamePassword);
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).post(url,formData).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          this.userUpdatepassword= false;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.userUpdatepassword= false;
          this.getUserArr();
        }else if(response.state==50200){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.userUpdatepassword= false;
          this.getUserArr();
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.userUpdatepassword= false;
        }
      })
    },
    openUpdateUser(){
      this.$confirm('是否修改用户?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.updateUser('editForm');
      }).catch(() => {
      });

    },
    updateUser(formName){
      this.$refs[formName].validate((valid) => {
        if(valid){
          let url = "http://localhost:9281/user-update-user";
          for (let i = 0; i < this.majorArr.length; i++) {
            console.log(11)
            if(this.majorArr[i].id==this.editForm.majorId){
              console.log(11)
              this.editForm.majorName = this.majorArr[i].majorName;
            }
          }

          for (let i = 0; i < this.classUpdateArr.length; i++) {
            console.log(22)
            if(this.classUpdateArr[i].id==this.editForm.classId){
              console.log(22)
              this.editForm.className = this.classUpdateArr[i].className;
            }
          }
          console.log(url);
          let formData = this.qs.stringify(this.editForm);
          let jwt = localStorage.getItem("localJwt");
          this.axios
              .create({
                'headers':{
                  'Authorization':jwt
                }
              }).post(url,formData).then((response)=> {
            let jsonResult = response.data;
            if(jsonResult.state==20000){
              this.dialogFormVisible=false;
              this.getUserArr();
              if (jsonResult.jwt!=null){
                localStorage.setItem("localJwt",jsonResult.jwt);
              }
            }else if(jsonResult.state==70100){
              this.$alert(jsonResult.message, '错误', {
                confirmButtonText: '确定',
                callback: action => {
                }
              });
              this.$router.push('/')
            } else if(response.state==40400){
              this.$alert(jsonResult.message, '错误', {
                confirmButtonText: '确定',
                callback: action => {
                }
              });
              this.getUserArr();
            }else {
              this.$alert(jsonResult.message, '错误', {
                confirmButtonText: '确定',
                callback: action => {
                }
              });
            }
          })
        }else {
          console.log('error submit!!');
          return false;
        }
      })
    },

    getStandard(user){
      let url = "http://localhost:9281/user-getStandard?id="+user.id;
      console.log(url);
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).get(url).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.editForm = jsonResult.data;
          console.log(this.editForm)
          this.dialogFormVisible=true;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    //批量删除用户
    openDeleteByIds(){
      if(this.multipleSelection.length<1){
        this.$alert("您未选中任何用户", '错误', {
          confirmButtonText: '确定'
        });
        return;
      }
      this.$confirm('是否删除用户?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteByIds();
      }).catch(() => {
      });
    },
    deleteByIds(){
      let url = "http://localhost:9281/user-deleteByIds";
      let ids = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        ids[i] = this.multipleSelection[i].id;
      }
      console.log(url);
      console.log("ids的值:"+ids)
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).post(url,ids).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          this.getUserArr();
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },



    //批量禁用用户
    closeStatus(){
      if(this.multipleSelection.length<1){
        this.$alert("您未选中任何用户", '错误', {
          confirmButtonText: '确定'
        });
        return;
      }
      this.$confirm('是否禁用用户?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.closeUpdateStatusByIds();
      }).catch(() => {
      });
    },
    closeUpdateStatusByIds(){
      let url = "http://localhost:9281/user-closeStatusByIds";
      let ids = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        ids[i] = this.multipleSelection[i].id;
      }
      console.log(url);
      console.log("ids的值:"+ids)
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).post(url,ids).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          this.getUserArr();
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },


    //批量开启用户
    openStatus(){
      if(this.multipleSelection.length<1){
        this.$alert("您未选中任何用户", '错误', {
          confirmButtonText: '确定'
        });
        return;
      }
      this.$confirm('是否启用用户?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.openUpdateStatusByIds();
      }).catch(() => {
      });
    },
    openUpdateStatusByIds(){
      let url = "http://localhost:9281/user-openStatusByIds";
      let ids = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        ids[i] = this.multipleSelection[i].id;
      }
      console.log(url);
      console.log("ids的值:"+ids)
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).post(url,ids).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          this.getUserArr();
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },


    //修改用户状态
    openUpdateStatus(user){
      this.$confirm('是否修改用户状态?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.updateStatus(user)
      }).catch(() => {
        this.getUserArr();
      });
    },
    updateStatus(user){
      let url = "http://localhost:9281/user-updateStatus";
      let formDate = "id="+user.id+"&status="+user.status;
      console.log(url);
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).post(url,formDate).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.$message({
            showClose: true,
            message: '修改成功',
            type: 'success'
          });
          this.getUserArr();
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    /*打开删除弹窗*/
    openDelete(user){
      this.$confirm('此操作将永久此用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.openDeleteById(user)
      }).catch(() => {
      });
    },
    openDeleteById(user){

      let url = "http://localhost:9281/user-delete";
      let formDate = "id="+user.id;
      console.log(url);
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          }).post(url,formDate).then((response)=> {
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.$message({
            showClose: true,
            message: '删除成功',
            type: 'success'
          });
          this.getUserArr();
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else if(response.state==40400){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定'
          });
          this.getUserArr();
        }else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })

    },
    //点击修改分页
    changePage(value){
      if(this.inputs.trim()==''){
        console.log(this.currentPage)
        this.$router.replace("?page="+value);
        this.selectUserByUser();
      }else {
        this.$router.replace("?page="+value);
        this.getUserArr();
      }

    },
    //刷新页面
    LoadUserList(){
      this.selectUser = {
        roleId:'',
        majorId:'',
        classId:'',
        username:'',
        trueName:''
      };
      this.selectUserByUser();
    },
    //加载用户列表
    selectUserByUser(){
      let page = this.$router.currentRoute.query.page;
      if(page<1||page==null){
        page=1;
      }
      let formData = this.qs.stringify(this.selectUser);
      let url = "http://localhost:9281/user-listByUserSelect?page="+page+"&"+formData;
      let jwt = localStorage.getItem("localJwt");
      console.log(url)
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          })
          .get(url).then((response)=>{
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          let page = this.$router.currentRoute.query.page;
          if(!page){
            page=1;
          }
          if(jsonResult.data.list.length==0&&page!=1){
            let page1= +this.$router.currentRoute.query.page-1;
            if(page1>2){
              this.$router.replace("?page="+this.$router.currentRoute.query.page-1);
            }
          }
          this.userArr = jsonResult.data.list;
          this.total = jsonResult.data.total;
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else{
          this.$alert(response.data.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    //加载角色列表
    getRoleInputs(){
      let url = 'http://localhost:9281/userRole/list-input';
      let jwt = localStorage.getItem("localJwt");
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          })
          .get(url).then((response)=>{
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.roleArr = jsonResult.data;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      });
    },
    //加载专业列表
    getMajorArr(){
      let url = "http://localhost:9281/major/list";
      let jwt = localStorage.getItem("localJwt");
      console.log(url);
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          })
          .get(url).then((response)=>{
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.majorArr = jsonResult.data;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else{
          this.$alert(response.data.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })


    },
    //加载班级列表
    getClassArr(){
      console.log(this.user)
      let url = "http://localhost:9281/class/list";
      let jwt = localStorage.getItem("localJwt");
      console.log(url);
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          })
          .get(url).then((response)=>{
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.classArr = jsonResult.data;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else{
          this.$alert(response.data.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    getClassUpdateArr(){
      console.log(this.user)
      let url = "http://localhost:9281/class/list?id="+this.editForm.majorId;
      let jwt = localStorage.getItem("localJwt");
      console.log(url);
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          })
          .get(url).then((response)=>{
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          this.classUpdateArr = jsonResult.data;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else{
          this.$alert(response.data.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    //暂时失效的userArr
    getUserArr(){
      let page = this.$router.currentRoute.query.page;
      if(page<1||page==null){
        page=1;
      }
      let url = "http://localhost:9281/user-list?page="+page;
      let jwt = localStorage.getItem("localJwt");
      console.log(url)
      console.log(url);
      this.axios
          .create({
            'headers':{
              'Authorization':jwt
            }
          })
          .get(url).then((response)=>{
        let jsonResult = response.data;
        if(jsonResult.state==20000){
          if(jsonResult.data.list.length==0){
            let page1= +this.$router.currentRoute.query.page;
            if(page1>2){
              this.$router.replace("?page="+page1-1);
            }
          }
          this.userArr = jsonResult.data.list;
          this.total = jsonResult.data.total;
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          if (jsonResult.jwt!=null){
            localStorage.setItem("localJwt",jsonResult.jwt);
          }
        }else if(jsonResult.state==70100){
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
          this.$router.push('/')
        } else{
          this.$alert(response.data.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    handleSelectionChange(val) {
      if (val.length==0){
        this.isMultipleSelection=false
      }else {
        this.isMultipleSelection=true
      }
      this.multipleSelection = val;
    }
  },
  mounted() {
    this.getRoleInputs();
    this.getMajorArr();
    this.getClassArr();
    this.selectUserByUser();
  }
}
</script>
